package com.itheima;

import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList list = new ArrayList<>();
        list.add("张三");
        list.add("张三");
        list.add("李四");
        list.add("李四");
        list.add("王五");
        list.add("王五");

        ArrayList<String> newlist = new ArrayList<>(new HashSet<String>(list));
        System.out.println(list);

        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("张三");
        hashSet.add("李四");
        hashSet.add("王五");
        hashSet.add("王五");
        hashSet.add("赵六");
        hashSet.add("田七");
        System.out.println(hashSet);
        //取数据
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }
      /*  for (int i = 0; i < hashSet.size(); i++){
        }*/
        //增强for循环 取数据
        for (String name : hashSet) {
            System.out.println("name="+name);
        }
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr){
            System.out.println(i);
        }
        //取数据（迭代器）
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        //取数据（lambda表达式）
        hashSet.forEach(s ->  System.out.println(s));
        //取数据（方法引用）
        hashSet.forEach(System.out::println);


    }
}
